package com.android.formula.task;

import java.util.ArrayList;

import android.content.Context;

import com.android.formula.common.MyApplication;
import com.android.formula.dao.NoteSubjectDao;
import com.android.formula.database.NoteDatabaseConnection;
import com.android.formula.model.NoteSubject;

/**
 * Get a Spot by Id
 */
public class GetNoteSubjectDBTask extends
		BaseDatabaseTask<NoteSubject, ArrayList<NoteSubject>> {

	public GetNoteSubjectDBTask(Context context,
			IDataEventHandler<ArrayList<NoteSubject>> dataEventHandler) {
		super(context, null, null, dataEventHandler);
	}

	@Override
	protected ArrayList<NoteSubject> execute() {
		NoteDatabaseConnection sqlt = MyApplication.getDatabaseConnection();
		if (sqlt == null) {
			return null;
		}

		sqlt.open();
		NoteSubjectDao dao = new NoteSubjectDao(NoteSubject.class, mContext,
				sqlt.getDatabase());
		ArrayList<NoteSubject> list = dao.getAll();
		sqlt.close();
		if (!list.isEmpty()) {
			return list;
		} else {
			return null;
		}
	}
}
